package game;

import javax.swing.*;
import java.awt.*;

public class PausePanel extends JPanel {
    private final GameWindow gameWindow;

    public PausePanel(GameWindow gameWindow) {
        this.gameWindow = gameWindow;
        setLayout(new GridBagLayout());
        setOpaque(false); // 半透明背景

        // 创建半透明背景
        JPanel contentPanel = new JPanel();
        contentPanel.setLayout(new GridLayout(2, 1, 0, 20));
        contentPanel.setBackground(new Color(0, 0, 0, 200));
        contentPanel.setBorder(BorderFactory.createEmptyBorder(30, 60, 30, 60));

        // 继续按钮
        JButton resumeButton = new JButton("继续游戏");
        resumeButton.addActionListener(e -> gameWindow.resumeGame());
        styleButton(resumeButton);

        // 退出按钮
        JButton quitButton = new JButton("返回主菜单");
        quitButton.addActionListener(e -> gameWindow.returnToMainMenu());
        styleButton(quitButton);


        contentPanel.add(resumeButton);
        contentPanel.add(quitButton);

        add(contentPanel);
    }

    private void styleButton(JButton button) {
        button.setFont(new Font("微软雅黑", Font.BOLD, 24));
        button.setPreferredSize(new Dimension(200, 60));
        button.setFocusPainted(false);
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        // 半透明黑色背景
        g.setColor(new Color(0, 0, 0, 150));
        g.fillRect(0, 0, getWidth(), getHeight());
    }
}
